﻿using _8Group.MES.ILiService;
using _8Group.MES.ILiService.DTO;
using _8Group.MES.LiService;
using _8Group.MES.Model.WM仓储管理;
using _8Group.MES.WorkStation;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace _8Group.MES.Web.Controllers
{
    /// <summary>
    /// 李明豫控制器(个人任务的所有视图和方法都写在该控制器里)
    /// </summary>
    public class LiController : Controller
    {
        private readonly ReturnOrderService _returnOrderService;
        
        private readonly    IWorkStationService _workStationService;
        private readonly IDVMachineryTypeService _dVMachineryTypeService;
        public LiController(IWorkStationService workStationService, IDVMachineryTypeService dVMachineryTypeService, ReturnOrderService returnOrderService)
        {
            _workStationService = workStationService;
            _dVMachineryTypeService = dVMachineryTypeService;
            _returnOrderService = returnOrderService;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 获取车间列表
        /// </summary>
        /// <returns></returns>
        public async Task<JsonResult> GetWorkShopList()
        {
            var workShopList = await _workStationService.GetWorkShopList();
            return Json(workShopList);
        }

        /// <summary>
        /// 获取生产工序
        /// </summary>
        /// <returns></returns>
        public async Task<JsonResult> GetProcessList()
        {
            var processList = await _workStationService.GetProcessList();
            return Json(processList);
        }

        /// <summary>
        /// 获取工作站列表
        /// </summary>
        /// <param name="workstationCode"></param>
        /// <param name="workstationName"></param>
        /// <param name="workshopID"></param>
        /// <param name="processID"></param>
        /// <returns></returns>
        public async Task<JsonResult> GetWorkStationList(string? workstationCode, string? workstationName, int? workshopID, int? processID, int pageIndex, int pageSize)
        {
            var workStationList = await _workStationService.GetWorkStationList(workstationCode, workstationName, workshopID, processID, pageIndex, pageSize);
            return Json(workStationList);
        }
        /// <summary>
        /// 修改计算单位页面
        /// </summary>
        /// <returns></returns>
        public IActionResult MeasuringUnitUpdate()
        {
            return View();
        }
        /// <summary>
        /// 添加工作站页面
        /// </summary>
        /// <returns></returns>
        public IActionResult WorkStationAdd()
        {
            return View();
        }
        /// <summary>
        /// 修改工作站页面
        /// </summary>
        /// <returns></returns>
        public IActionResult WorkStationUpdate()
        {
            return View();
        }
        /// <summary>
        /// 添加工作站
        /// </summary>
        /// <param name="workStationAddDTO"></param>
        /// <returns></returns>
        public async Task<JsonResult> AddWorkStation(WorkStationAddDTO workStationAddDTO)
        {
            var result = await _workStationService.AddWorkStation(workStationAddDTO);
            return Json(result);
        }
        /// <summary>
        /// 修改工作站
        /// </summary>
        /// <param name="workStationUpdateDTO"></param>
        /// <returns></returns>
        public async Task<JsonResult> UpdateWorkStation(WorkStationUpdateDTO workStationUpdateDTO)
        {
            var result = await _workStationService.UpdateWorkStation(workStationUpdateDTO);
            return Json(result);
        }

        /// <summary>
        /// 删除工作站
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<JsonResult> DeleteWorkStation(int id)
        {
            var result = await _workStationService.DeleteWorkStation(id);
            return Json(result);
        }

        public IActionResult DV_Machinery_Type()
        {
            return View();
        }
        /// <summary>
        /// 获取全部设备类型设置
        /// </summary>
        /// <param name="machineTypeName"></param>
        /// <param name="enableFlag"></param>
        /// <returns></returns>
        public async Task<JsonResult> GetDVMachineryType(string? machineTypeName, string? enableFlag)
        {
            var result= await _dVMachineryTypeService.GetDVMachineryType(machineTypeName, enableFlag);
            return Json(result);
        }
        /// <summary>
        /// 修改设备类型设置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<JsonResult> UpdateMachineryType(UpdateMachineryDTO input)
        {
            var result = await _dVMachineryTypeService.UpdateMachineryType(input);
            return Json(result);
        }

        public IActionResult DVMachineryTypeUpdate()
        {
            return View();
        }
        public IActionResult ReturnOrder()
        {
            return View();
        }
        public IActionResult AddReturnOrderView()
        {
            return View();
        }

        public IActionResult UpdateReturnOrderView()
        {
            return View();
        }

        /// <summary>
        /// 添加退回订单
        /// </summary>
        /// <returns></returns>
        [HttpGet,Route("/Li/AddReturnOrders")]
        public IActionResult AddReturnOrders(ReturnOrder input)
        {
            var workDto = _returnOrderService.AddReturnOrder(input);
            return Ok(workDto);
        }

        /// <summary>
        /// 删除退回订单
        /// </summary>
        /// <returns></returns>
        public IActionResult DeletReturnOrder(int id)
        {
            var returnOrder = _returnOrderService.DeletReturnOrder(id);
            return Ok(returnOrder);
        }

        /// <summary>
        /// 根据id获取退回订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult GetReturnOrder(int id)
        {
            var works = _returnOrderService.GetReturnOrder(id);
            return Ok(works);
        }

        /// <summary>
        /// 更新退回订单
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateReturnOrder(UpdateReturnOrderDto input)
        {
            var wang = _returnOrderService.UpdateReturnOrder(input);
            return Ok(wang);
        }
        public IActionResult AddReturnOrder()
        {
            return View();
        }
    }
}
